package a10_动态规划;

/**
 * <p>
 * a02_斐波那契数复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/12
 */
public class a02_斐波那契数复习2 {
    public int fib(int n) {
        //dp[i]:第i个数的斐波那契数的值
        //递推公式：dp[i] = dp[i-1] + dp[i-2]
        //初始化：dp[0] = 0 dp[1] = 1
        if(n <= 1){
            return n;
        }
        int[] dp = new int[n+1];
        dp[0] = 0;
        dp[1] = 1;
        for (int i = 2; i <= n; i++) {
            dp[i] = dp[i-1] + dp[i-2];
        }
        return dp[n];
    }
}
